package com.example.xinhuazidian.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.xinhuazidian.R

class QianziwenAdapter(
    private val spells: MutableList<String>,
    private val paragraphs: MutableList<String>
) :
    RecyclerView.Adapter<QianziwenAdapter.MyViewHolder>() {

    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val tvSpells: TextView = view.findViewById(R.id.tvSpells)
        val tvParagraphs: TextView = view.findViewById(R.id.tvParagraphs)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.item_qianziwen, parent, false)
        return MyViewHolder(view)
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        val spells = spells[position]
        val paragraphs = paragraphs[position]
        with(holder) {
            tvSpells.text = spells
            tvParagraphs.text = paragraphs
        }
    }

    override fun getItemCount() = spells.size
}

